#ifndef __Tools_H
#define __Tools_H

#ifdef APM32E10X_HD
	#include "apm32e10x_misc.h"
#elif defined AT32F403AVGT7
	#include "at32f403a_407_misc.h"
#else
	#include "apm32f10x_misc.h"
#endif

#include "BoardData.h"
#include <math.h>
#if card_type_sel > 0 || BLE_WIFY_EN > 0
#include <stdbool.h>
#endif

#include "stdio.h"

uint16_t getArrayMax(uint16_t *arrDatas, uint8_t arrSize);
uint16_t getArrayAverage(uint16_t *arrDatas, uint8_t arrSize);
uint32_t getSquareSum(uint16_t *arrDatas, uint8_t arrSize);
void arrPostData(uint16_t *arrDatas, uint8_t arrSize,uint16_t addData);
void arr8PostData(uint8_t *arrDatas, uint8_t arrSize,uint8_t addData);
//void arrCPPostData(uint8_t *arrDatas, uint8_t arrSize,uint16_t addData);
//void arrPostDelayTask(uint16_t *arrDatas[],uint8_t taskSize,uint8_t dataSize);
//uint8_t isFloatSame(float *a,float *b,float err);
//uint8_t analysis_cp_datas(uint8_t *arrDatas, uint8_t arrSize);
uint8_t getFaultCode(uint16_t faultBitMask);
void arrAllIs(uint8_t setValue,uint8_t *arrDatas, uint8_t arrSize);
void delayn50us(uint16_t nus);
void delaynus(uint16_t nus);

#if card_type_sel > 0 || BLE_WIFY_EN > 0
void encryptStr(unsigned char *str,unsigned char *pwd,unsigned char csize);
bool isSameArr(unsigned char *arr1,unsigned char *arr2,unsigned char size);
#if BLE_WIFY_EN > 0
int8_t isContainArr(unsigned char *arrContainer,unsigned char *arrBeContain,unsigned char ctnSize,unsigned char bectnSize);
void appendArr(unsigned char *originArr,unsigned char *appendArr,unsigned char insertPosi,unsigned char appSize);
uint8_t strLenMy(unsigned char *arr,unsigned char size);
bool isArrAllTheValue(uint8_t theValue,uint8_t *arrDatas, uint8_t arrSize);
int8_t getCharPosiInArr(uint8_t theChar,uint8_t *arr, uint8_t arrSize);
uint16_t strArrToHex(uint8_t *strArr, uint8_t Len);
void hexCharArrToHex(uint8_t *strArr, uint8_t Len,uint8_t *targetHexArr);
void xw_endecode(uint8_t *input, uint8_t ilen, uint8_t *key, uint8_t keyLen, uint8_t *output);
#endif
#endif

#if finger_sensor_type > 0
uint16_t getCheckSum_16Bit(uint8_t *dataArr,uint8_t start_idx,uint16_t end_idx);
#endif

#if CRC_Check  > 0
uint16_t CRC16(uint8_t * pMsg, uint16_t Len);
#endif

#if SEND_RTC_EN > 0
//void tmrTimeAdd(int8_t *timerData,uint8_t dataLen);
uint8_t hex_to_bcd(uint8_t hex_value);
uint8_t bcd_to_hex(uint8_t bcd_value);
void getTmrShow(int8_t *timerData,uint8_t dataLen);
#endif

uint16_t intPow(uint8_t base,uint8_t index);
uint16_t strArrToInt(uint8_t *strArr, uint8_t Len);

#endif
